package edit;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import db.DBManager;

public class UserEditServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, 
									HttpServletResponse resp)
			throws ServletException, IOException {
		String id = req.getParameter("id");
		try {
			//	データベースと接続
			Connection con = DBManager.getConnection();
			String sql = "select * from UserAccount where id = ?";
			PreparedStatement ps = con.prepareStatement(sql);
			ps.setString(1, id);
			
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				MakinoEdit makino = new MakinoEdit();
				makino.setId( rs.getString("id") );
				makino.setName( rs.getString("name") );
				makino.setPassword(rs.getString("password"));
				req.setAttribute("makino", makino);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}
		//	編集画面へ遷移
		RequestDispatcher dispatcher = 
				req.getRequestDispatcher("UserEdit.jsp");
		dispatcher.forward(req, resp);
	}
}
